package nine.test_9_6;

import java.util.Scanner;
import java.util.Stack;

public class TestMain2 {
    static boolean[] bs;
    static String minStr = null;
    static Stack<Integer> stack = new Stack<>();
    static  Stack<Integer> minStack = new Stack<>();
    static int k = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        bs = new boolean[n];
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            stack.push(arr[i]);
            bs[i] = true;
            k++;
            dfs(arr,stack);
            stack.pop();
            k--;
            bs[i] = false;
        }
        System.out.println(minStr);
    }
    private static void dfs(int[] arr,Stack<Integer> stack) {
        if(k == arr.length) {
            Stack<Integer> tmpStack = new Stack<>();
            while (stack.size() > 0) {
                tmpStack.push(stack.pop());
            }
            StringBuilder str = new StringBuilder();
            while (tmpStack.size() > 0) {
                int k = tmpStack.pop();
                stack.push(k);
                str.append(k);
            }
            if (minStr == null) {
                minStr = str.toString();
            } else {
                int i = 0;
                int j = 0;
                String tmp = str.toString();
                while (i < minStr.length() && j < tmp.length()) {
                    while (i < minStr.length() && j < tmp.length() && (minStr.charAt(i) < '0' || minStr.charAt(i) > '9') ) {
                        i++;
                    }
                    while (i < minStr.length() && j < tmp.length() && (tmp.charAt(j) < '0' || tmp.charAt(j) > '9')) {
                        j++;
                    }
                    while (i < minStr.length() && j < tmp.length() && tmp.charAt(j) == minStr.charAt(i)) {
                        i++;
                        j++;
                    }
                    if(i < minStr.length() && j < tmp.length() && minStr.charAt(i) > tmp.charAt(j)) {
                        minStr = tmp;
                        minStack = stack;
                        break;
                    }
                    break;
                }
            }
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            if(!bs[i]) {
                stack.push(arr[i]);
                bs[i] = true;
                k++;
                dfs(arr,stack);
                stack.pop();
                k--;
                bs[i] = false;
            }
        }
    }
}
